package com.whu.waterworks.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.GisListItemDto;
import com.whu.waterworks.model.Stationnumposition;
import com.whu.waterworks.model.WaterPlant;
import com.whu.waterworks.service.StationnumpositionService;
import com.whu.waterworks.service.WaterPlantService;

public class GisBasicInfoAction extends ActionSupport{
     /**
	 * 
	 */
	private static final long serialVersionUID = -5448342538244485644L;
	private String code;
    private List<GisListItemDto> list;
 	private WaterPlantService waterPlantService;
	private StationnumpositionService stationnumpositionService;
	
     public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public List<GisListItemDto> getList() {
		return list;
	}
	public void setList(List<GisListItemDto> list) {
		this.list = list;
	}
	public WaterPlantService getWaterPlantService() {
		return waterPlantService;
	}
	public void setWaterPlantService(WaterPlantService waterPlantService) {
		this.waterPlantService = waterPlantService;
	}
	public StationnumpositionService getStationnumpositionService() {
		return stationnumpositionService;
	}
	public void setStationnumpositionService(
			StationnumpositionService stationnumpositionService) {
		this.stationnumpositionService = stationnumpositionService;
	}
	public String getWaterplants()
     {
		 list = new ArrayList<>();
		 List<WaterPlant> waterPlants = waterPlantService.getAllWaterPlants();
		 if(waterPlants!=null)
		 {
			 for(WaterPlant waterPlant : waterPlants)
			 {
				 GisListItemDto dto = new GisListItemDto();
				 dto.setCode(waterPlant.getWaterPlantCode());
				 dto.setName(waterPlant.getWaterPlantName());
				 list.add(dto);
			 }
		 }


    	 return SUCCESS;
     }
     public String getStationsOfWaterplants()
     {
    	 list = new ArrayList<>();
    	 List<Stationnumposition>  stationnumpositions = stationnumpositionService.findAll(code);
    	 if(stationnumpositions!=null)
    	 {
             for(Stationnumposition stationnumposition : stationnumpositions)
             {
            	 String stationCode = stationnumposition.getStationnum();
            	 if(!stationCode.endsWith("00"))
            	 {
                	 GisListItemDto dto  =new GisListItemDto();
                	 dto.setCode(stationCode);
                	 dto.setName(stationnumposition.getPositionname());
                	 list.add(dto);
            	 }

             }
    	 }
    	 return SUCCESS;
     }
}
